/****************************************************************
 * I am the AC 130 vs Pirate game. I allow the user to control an 
 * AC130 gunship in the hunt for Modern day pirates. The player  
 * will be allowed to roam free across a section of ocean/coastline.  
 * In the water there will be four types of vessels: Merchant  
 * ships that the player must protect, Pirate ships that the player  
 * must identify and destroy, Fishing boats that look like Pirate  
 * ships that the player must not destroy, and Friendly Navy ships  
 * that can capture pirates for extra points. Time permitting there  
 * may also be ground targets to attack. 
 *
 * Key elements of this project will be the Player/AC130, the Ships,  
 * the ShipAI system, the collision grid, the debris controller, the  
 * Ground/Water, Clouds, and scoring system. This project will make  
 * use of an external text file to store useful game parameters,  
 * thus allowing us to play balance the game without recompiling  
 * the executable. 
 *****************************************************************
 * I am the Point Class I contain an x and y value to represent a 
 * point in 2d space. I have functions that can rotate and translate
 * my value by certain factors.
 *****************************************************************/

#include <math.h>
#include "point.h"


/*****************************************************************
 * I am the constructor, I initilize the internal values
 ******************************************************************/
Point::Point(){
	x = y = 0;
}

/*****************************************************************
 * I am the destructor, I exist for good form
 ******************************************************************/
Point::~Point(){}


/*****************************************************************
 * I am the allocator function I set this PozePoint to the value in
 * the tgt Poze point
 ******************************************************************/
void Point::Copy(Point * tgt){
	x = tgt->x;
	y = tgt->y;
}


/*****************************************************************
 * I am the distance finder
 ******************************************************************/
float Point::DistTo(Point * tgt){
	float dx = x - tgt->x ;
	float dy = y - tgt->y;
	return sqrt(dx*dx + dy*dy);
}

/*****************************************************************
 * I am the angel finder I return the angel in degrees 
 ******************************************************************/
float Point::AngTo(Point * tgt){
	float dx = tgt->x - x ;
	float dy = tgt->y - y;
	float hyp = sqrt(dx*dx + dy*dy);
		// return 0 if points are on top of each other
	if(hyp == 0)	return 0;

	if(dx > 0){
		return acos(dy/hyp)*57.29579;
	} 
	
	return acos(dy/hyp)*-57.29579;

}


/*****************************************************************
 * I am the angel finder I return the angel in degrees 
 ******************************************************************/
void Point::RotateBy(float degree)
{
	float DtoR = 0.0174532925;
	float si = sin(degree*DtoR);
	float co = cos(degree*DtoR);
	float oldX = x;
	float oldY = y;

		// X remains unchainged
	x = co*oldX + si*oldY;
	y = co*oldY - si*oldX;

	return;
}


/*****************************************************************
 * I am the angel finder I return the angel in degrees 
 ******************************************************************/
void Point::Translate(float dx, float dy){
	x += dx;
	y += dy;
}